package com.etc.service.impl;

import java.util.List;

import com.etc.dao.EvaluateDao;
import com.etc.dao.GoodsDao;
import com.etc.dao.impl.EvaluateDaoImpl;
import com.etc.dao.impl.GoodsDaoImpl;
import com.etc.entity.Evaluate;
import com.etc.entity.Goods;
import com.etc.entity.ShopEvaluate;
import com.etc.service.EvaluateService;
import com.etc.tools.PageData;

/**

* <p>Title: EvaluateServiceImpl</p>

* <p>Description: </p>

* @author knowno

* @date 2021年1月11日

*/
public class EvaluateServiceImpl implements EvaluateService {
	EvaluateDao evaluateDao=new EvaluateDaoImpl();
	/**
	 * 添加商品评价
	 */
	@Override
	public boolean addEvaluate(Evaluate evaluate) {
		// TODO Auto-generated method stub
		GoodsDao goodsDao=new GoodsDaoImpl();
		//添加商品评价前，判断商品是否已经下架
		Goods goods=goodsDao.queryOneGoods(evaluate.getGoodsid());
		if (goods.getGoodsstate()==0) {
			return false;
		}
		return evaluateDao.addEvaluate(evaluate);
	}
	/**
	 * 分页查找
	 */
	@Override
	public PageData<Evaluate> queryPageEvaluate(int page, int pageSize, int goodsid) {
		//判断页码是否正确
		if (page < 1) {
			page = 1;
		} else if (page > pageSize) {
			page = pageSize;
		}
		return evaluateDao.queryPageEvaluate(page, pageSize, goodsid);
	}
	/**
	 * 删除评价
	 */
	@Override
	public boolean delEvaluate(int id) {
		// TODO Auto-generated method stub
		return evaluateDao.delEvaluate(id);
	}
	/**
	 * 不分页查询评价
	 */
	@Override
	public List<Evaluate> queryEvaluate(int goodsid) {
		// TODO Auto-generated method stub
		return evaluateDao.queryEvaluate(goodsid);
	}
	/**
	 * 个人店铺商品评价
	 */
	@Override
	public PageData<ShopEvaluate> queryPageshopEvaluate(int page, int pageSize, int shopid) {
		// TODO Auto-generated method stub
		return evaluateDao.queryPageshopEvaluate(page, pageSize, shopid);
	}

}
